package com.lnu.information.util;

import com.lnu.information.common.Constant;
import com.lnu.information.dto.QueryCompanyRequestDTO;
import com.lnu.information.exception.QueryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author : jian.zhang-2
 * @description:
 * @date : Create in 4:17 PM 2022/3/10
 * @modified By :
 */
public class ValidateUtil {

    private static final Logger logger = LoggerFactory.getLogger(ValidateUtil.class);


    /***
     * 校验参数字段
     * @param param
     * @param name
     */
    public static void checkRequestParam(Object param, String name){
        if(CheckUtils.isEmpty(param)) {
            logger.info(name+"不能为空");
            throw new QueryException(QueryException.QueryExceptionEnum.ILLEGAL_PARAM_EXCEPTION).newInstance(name+"不能为空");
        }
    }

    /***
     * 查询表名是否存在
     * @param tableName
     */
    public static void checkTableName(String tableName) {
        String[] tableNames = Constant.TABLE_NAMES;
        for(int i = 0; i < tableNames.length; i++){
            if(tableNames[i].equals(tableName)){
                return;
            }
        }
        throw new QueryException(QueryException.QueryExceptionEnum.ILLEGAL_PARAM_EXCEPTION).newInstance("表名" + tableName + "传递错误");
    }

    //通过表名校验参数
    public static void checkParamByTableName(String tableName, QueryCompanyRequestDTO queryCompanyRequestDTO) {
        if("company".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("company_listedcompany_equityholding".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyId());
        }else if("company_listedcompany_detailinfor".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_detailInfor_FullName());
        }else if("company_listedcompany".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyId());
        }else if("company_listedcompany_additionalissue".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_additionalIssue_FullName());
        }else if("company_listedcompany_allotmentcondition".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_allotmentCondition_FullName());
        }else if("company_listedcompany_dividendmatter".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_dividendMatter_FullName());
        }else if("company_listedcompany_equitytransfer".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_equityTransfer_FullName());
        }else if("company_listedcompany_executiveholdingchanges".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_executiveholdingchanges_FullName());
        }else if("company_listedcompany_executiveinfor".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_executiveInfor_FullName());
        }else if("company_listedcompany_fundraisingsource".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_fundRaisingSource_FullName());
        }else if("company_listedcompany_handofviolation".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_handofViolation_FullName());
        }else if("company_listedcompany_holderholdingchanges".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_holderholdingchanges_FullName());
        }else if("company_listedcompany_holdernumber".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyId());
        }else if("company_listedcompany_institutionholddetail".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_institutionholdDetail_FullName());
        }else if("company_listedcompany_institutionholdsummary".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_institutionholdSummary_FullName());
        }else if("company_listedcompany_ipoinstitution".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_ipoInstitution_organizationName());
        }else if("company_listedcompany_issuerelated".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_issueRelated_FullName());
        }else if("company_listedcompany_pledgethaw".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyId());
        }else if("company_listedcompany_projectinvestment".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_projectInvestment_FullName());
        }else if("company_listedcompany_purchaseandmergers".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_purchaseandMergers_FullName());
        }else if("company_listedcompany_relatedtransactions".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_relatedTransactions_FullName());
        }else if("company_listedcompany_toptencurrentshareholders".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompany_listedCompany_topTenCurrentShareholders_FullName());
        }

        //bbd
        else if("ktgg".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getAccuser());
        }else if("legal_dishonest_persons_subject_to_enforcement".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("legal_persons_subject_to_enforcement".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getPname());
        }else if("manage_bidwinning".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("manage_recruit".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("overseas_investment".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getDomesticInvestSubject());
        }else if("prop_domain_website".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getOrganizerName());
        }else if("qyxx_finalshareholder".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_jqka_cwzb_yhzx".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_mordetail".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_jyyc".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_liquidation".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("manage_tender".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_basic".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_jqka_cwbd".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_sharesfrost".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_baxx".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getName());
        }else if("qyxx_fzjg_merge".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_gdxx".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getShareholderName());
        }else if("qyxx_jqka_cwzb_xjll".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_jqka_cwzb_zcfz".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_jqka_ipo_fxxg".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_jqka_cwzb_zhsy".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_jqka_cwzb_zhzb".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_jqka_ipo_basic".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_sharesimpawn".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("qyxx_wanfang_zhuanli".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("risk_punishment".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("risk_tax_owed".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }else if("xgxx_shangbiao".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getApplicantName());
        }else if("qyxx_bgxx_merge_clean".equals(tableName)){
            checkParam(queryCompanyRequestDTO.getCompanyName());
        }
    }

    private static void checkParam(String param) {
        if(CheckUtils.isEmpty(param)) {
            logger.info(param+"不能为空");
            throw new QueryException(QueryException.QueryExceptionEnum.ILLEGAL_PARAM_EXCEPTION).newInstance(param+"不能为空");
        }
    }
}
